package com.gexiaobao.pigeon.viewmodel

import androidx.lifecycle.MutableLiveData
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.DepositApplyResponse
import com.gexiaobao.pigeon.app.model.bean.LoftPayInfoResponse
import com.gexiaobao.pigeon.app.model.param.CancelPayLoftParam
import com.gexiaobao.pigeon.app.model.param.ConsumeApplyLoftParam
import com.gexiaobao.pigeon.app.model.param.LoftPayInfoParam
import com.gexiaobao.pigeon.app.model.param.PayParam
import com.gexiaobao.pigeon.app.network.apiService
import com.gexiaobao.pigeon.app.util.RxToast
import me.hgj.jetpackmvvm.base.appContext
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState

/**
 * @Author      : hxw
 * @Date        : 2024/4/2 14:54
 * @Describe    :
 */
class PayViewModel : BaseViewModel() {

    /** 二维码公棚赛鸽申请支付 */
    var consumeApplyLoftResult: MutableLiveData<Any> = MutableLiveData()
    fun consumeApplyLoftPigeon(param: ConsumeApplyLoftParam) {
        request({ apiService.consumeApplyLoftPigeon(param) }, {
            consumeApplyLoftResult.value = it
        }, {
            RxToast.showToast(it.msg)
        })
    }

    /** 取消二维码公棚赛鸽申请支付 */
    var cancelPayLoftResult: MutableLiveData<Any> = MutableLiveData()
    fun cancelPayLoftPigeon(param: CancelPayLoftParam) {
        request({ apiService.cancelPayLoftPigeon(param) }, {
            cancelPayLoftResult.value = it
        }, {
            RxToast.showToast(it.msg)
        })
    }

    /** 确认支付 */
    val payResult = MutableLiveData<ResultState<DepositApplyResponse>>()
    fun commitPay(body: PayParam) {
        request(
            { apiService.commitPay(body) },
            payResult,
            false,
            appContext.getString(R.string.loading)
        )
    }

    /** 生成公棚赛鸽支付订单 */
    var loftPayInfoResult: MutableLiveData<LoftPayInfoResponse> = MutableLiveData()
    fun genLoftPayInfo(param: LoftPayInfoParam) {
        request({ apiService.genLoftPayInfo(param) }, {
            loftPayInfoResult.value = it
        }, {
            RxToast.showToast(it.msg)
        })
    }
}